<?php if(! defined('BASEPATH'))exit('No direct script access allowed');
class model extends My_Controller {
	function __construct(){
		parent::__construct();
	}
	function admin_index(){
		if(!CIUser::checkPermission("admin")){
			show_404();
		}
		$this->load->model("model_model","modelModel");
		$model = $this->modelModel->get();
		$this->_assign("models",$model);
		$this->_fetch('admin_index');
	}
	function add_model($id=""){
		if(!CIUser::checkPermission("admin")){
			show_404();
		}
		$_post = $this->input->post();

		if(!empty($id)){
		 $this->load->model("model_model","modelModel");
		 $modelform=$this->modelModel->get($id);
		 $this->_assign('modeledite',$modelform);
		 $this->_fetch('admin_form');

		}else{

    $this->modelModel->add($_post);
		redirect("model/admin_index");
	  }
	}

	function admin_form(){
		if(!CIUser::checkPermission("admin")){
			show_404();
		}
		$this->load->model("brand_model","brandModel");
		$brand = $this->brandModel->get();
		$this->_assign("brand",$brand);
		$this->_fetch('admin_form');
	}

  function admin_delete($id=""){
  	if(!CIUser::checkPermission("admin")){
			show_404();
		}
	 	$this->db->delete('ci_model',array('mod_id'=>$id));
	 	redirect('model/admin_index');
 }

}